import { message } from 'antd';


export const Error = (msg) => {
    message.info({
        content: msg,
        className: 'custom-class',
        style: {
            marginTop: '50%',
        },
    });
}
export const Success = (msg) => {
    message.info({
        content: msg,
        className: 'custom-class',
        style: {
            marginTop: '50%',
        },
    });
}
// 后台乱码转换
export const convert = (text) => {
    let element = document.createElement("p");
    element.innerHTML = text;
    let output = element.innerText || element.textContent;
    element = null;
    return output;
}

/**
 * 数据返回统一处理函数
 * @param {*} response
 * @param {*} successMsg 成功提示
 */
export const processData = (response, successMsg) => {
    let result={};
    try {
        if (typeof response != 'object') {
            Error('数据返回出错：1、请确保服务运行正常；2、请确保您的前端工程代理服务正常；3、请确认您已在本地登录过应用平台');
            return {result:null};
        }
        if (response.code == '200') {
            if (successMsg) {
                Success(successMsg);
            }
            result.status = 'success';
            result.data = response.data;
            return { result };
        } else {
            Error(`${response.message||'request error'}`);
            result.status = 'error';
            return { result };
        }
    } catch (e) {
        return {result};
    }
}


